package com.cloud.controller;

import com.cloud.config.Log;
import com.cloud.myInterface.Factory;
import com.cloud.pojo.ReagentResult;
import com.cloud.service.ReagentResultService;
import com.cloud.tools.CommonResult;
import com.cloud.tools.CommonResultFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * @Author: Tangtao
 * @Date: 2022/4/14 21:18
 * @Description: Information about the result of the reagent bottle
 * @ClassName: ReagentResultController
 */

@RestController
public class ReagentResultController {

    @Resource
    private ReagentResultService reagentResultService;

    private final Factory resultFactory = new CommonResultFactory();

    /* 用户对于检测结果的查询 */
    @GetMapping(value = "/result/check")
    public CommonResult checkTestResult() {
        List<ReagentResult> reagentResults = reagentResultService.checkTestResultById();
        return resultFactory.getResultInstance(200, "查询成功", reagentResults);
    }

    /* 医护人员进行检测结果的单个上传 */
    @Log(value = "核酸检测结果上传")
    @PostMapping(value = "/result/doctorSend/one")
    public CommonResult saveTestResultOnce(@RequestBody ReagentResult reagentResult) {
        if (reagentResultService.saveTestResultOnce(reagentResult))
            return resultFactory.getResultInstance(200, "保存成功", 1);
        return resultFactory.getResultInstance(500, "保存失败", 0);

    }

    /* 医护人员进行检测结果的批量上传 */
    @Log(value = "核酸检测结果上传")
    @PostMapping(value = "/result/doctorSend/batch")
    public CommonResult saveTestResultBatch(@RequestBody List<ReagentResult> reagentResultMap) {
        if (reagentResultService.saveTestResultBatch(reagentResultMap))
            return resultFactory.getResultInstance(200, "保存成功", 1);
        return resultFactory.getResultInstance(500, "保存失败", 0);
    }

    /* 管理员进行检测结果的修改 */
    @Log(value = "修改核酸检测结果")
    @PostMapping(value = "/result/managerUpdate")
    public CommonResult resultManage(@RequestBody ReagentResult reagentResult) {
        if (reagentResultService.resultManage(reagentResult))
            return resultFactory.getResultInstance(200, "修改成功", 1);
        return resultFactory.getResultInstance(500, "修改失败", 0);
    }

    @PostMapping(value = "/reagent/ManagerGetResult")
    public CommonResult getResultFromUserId(@RequestBody Map<String,String> map){
        return resultFactory.getResultInstance(200,"查询成功",
                reagentResultService.getResultByIdForManager(map));
    }

    @GetMapping(value = "/reagent/Allresult")
    public CommonResult getAllResult(){
        return resultFactory.getResultInstance(200,"查询成功",
                reagentResultService.getAllResult());
    }

    @Log(value = "删除核酸检测结果")
    @PostMapping(value = "/result/delete")
    public CommonResult resultDelete(@RequestBody Map<String,String> map){
        if(reagentResultService.deleteResult(map.get("reagentBottleId")))
            return resultFactory.getResultInstance(200, "操作成功", 1);
        return resultFactory.getResultInstance(500, "操作失败", 0);
    }


}
